﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;

public partial class reports_userControls_TracID_Summary : System.Web.UI.UserControl
{

    private String _TopLevel = String.Empty;

    public String TopLevel
    {
        get { return _TopLevel; }
        set { _TopLevel = value; }
    }

    private String _RollUpUnit = String.Empty;
    public String RollUpUnit
    {
        get { return _RollUpUnit; }
        set { _RollUpUnit = value; }
    }

    private string _RollupTitle = String.Empty;

    public string RollupTitle
    {
        get { return _RollupTitle; }
        set { _RollupTitle = value; }
    }

    public String Props()
    {
        string sProps = Char.IsNumber(Eval("TRAC_ID").ToString(), 0) ? " Properties" : "";
        return Eval("PROPERTY_NM").ToString() + (Eval("TRAC_ID").ToString().Length > 0 ? " (" : "") + Eval("TRAC_ID").ToString() + sProps + (Eval("TRAC_ID").ToString().Length > 0 ? ")" : "");
    }


    protected void Page_Load(object sender, EventArgs e)
    {

        if (Request.QueryString["ROLLUP_TYPE"] != null)
        {
            TopLevel = Request.QueryString["ROLLUP_TYPE"];
            RollUpUnit = Request.QueryString["ROLLUP_ID"];
            RollupTitle = Request.QueryString["Title"].Trim().Split(':')[0];
        }

        string TopLevelFilter = String.Format("{1}='{0}'", RollUpUnit.Replace("'", "''"), TopLevel);

        String ManagerLevel = String.Empty;
        String RollUpFilter = String.Empty;

        switch (TopLevel)
        {
            case "Manager":
                String[] tmpArr = RollUpUnit.Split(':');


                string RollUpMgr = tmpArr[0];
                ManagerLevel = tmpArr.Length == 1 ? "0" : tmpArr[1];

                switch (ManagerLevel)
                {
                    case "1":
                        ////SQLFilter = String.Format(" B.TRAC_ID IN (SELECT TRAC_ID FROM MIS.ACC_TRAC_INFO WHERE AREA_MGR='{0}' GROUP BY 1)", RollUpFilter);
                        //fvPenetration.DataSource = (new MarketPenetration()).ByAreaMgr(RollUpMgr);
                        //fvPenetration.DataBind();
                        break;

                    case "2":
                        //fvPenetration.DataSource = (new MarketPenetration()).ByAcctMgr(RollUpMgr);
                        //fvPenetration.DataBind();
                        break;


                    case "0":
                        RollUpFilter = ConfigurationManager.AppSettings[RollUpMgr];
                        //fvPenetration.DataSource = (new MarketPenetration()).ByRegion(RollUpFilter);
                        //fvPenetration.DataBind();
                        break;

                    default:
                        break;
                }
                //Heading1.Text = RollUpMgr + " ROLL UP";
                break;

            case "State":
                //if (RollUpUnit == "ZZ")
                //{
                //    RollUpFilter = ConfigurationManager.AppSettings[RollUpUnit];
                //    //SQLFilter = String.Format(" B.REGION='{0}'", RollUpFilter);
                //    RollupTitle = RollUpFilter;
                //    //fvPenetration.DataSource = (new MarketPenetration()).ByRegion(RollUpFilter);
                //    //fvPenetration.DataBind();
                //    break;
                //}
                //SQLFilter = String.Format(" SUBSTR(B.TRAC_ID,1,2) = '{0}'", RollUpUnit);
                //Heading1.Text = (String)((Hashtable)Cache["ACC_STATES"])[RollUpUnit] + " ROLL UP";
                ////Heading1.Text = RollUpUnit + " ROLL UP";
                //fvPenetration.DataSource = (new MarketPenetration()).ByState(RollUpUnit);
                //fvPenetration.DataBind();
                break;

            case "Market":
                //fvPenetration.DataSource = (new MarketPenetration()).ByMarket(RollUpUnit);
                //fvPenetration.DataBind();
                break;

            case "Portfolio":
            case "Portfolios":
                //fvPenetration.DataSource = (new MarketPenetration()).ByPortfolio(RollUpUnit);
                //fvPenetration.DataBind();
                break;

            case "Property":
                //SQLFilter = String.Format(" B.TRAC_ID ='{0}'", RollUpUnit);
                TopLevelFilter = String.Format("TRAC_ID='{0}'", RollUpUnit);

                //Heading1.Text = RollUpUnit.ToUpper() + " ROLL UP";
                break;

            default:
                break;
        }

    }
    protected void fvPenetration_PageIndexChanging(object sender, FormViewPageEventArgs e)
    {

    }

    protected string IPTV_REVENUE()
    {

        return "0";
    }
    protected string HSIA_REVENUE()
    {

        return "0";
    }
    protected string VOIP_REVENUE()
    {
        return "0";

    }
    protected string OTHER_UVERSE_REVENUE()
    {

        return "0";
    }

    protected void ACCT_MGRLabel_Click(object sender, EventArgs e)
    {
        TopLevel = "Manager";
        RollupTitle = ((LinkButton)sender).Text;
        RollUpUnit = RollupTitle + ":2";

    }

    protected void lbl_Portfolio_Click(object sender, EventArgs e)
    {
        TopLevel = "Portfolio";
        RollupTitle = ((LinkButton)sender).Text;
        RollUpUnit = RollupTitle;

    }
    protected void AREA_MGRLabel_Click(object sender, EventArgs e)
    {
        TopLevel = "Manager";
        RollupTitle = ((LinkButton)sender).Text;
        RollUpUnit = RollupTitle + ":1";

    }
    protected void STATE_CDLabel_Click(object sender, EventArgs e)
    {
        TopLevel = "State";
        RollupTitle = ((LinkButton)sender).Text;
        RollUpUnit = RollupTitle;


    }
    protected void MARKETLabel_Click(object sender, EventArgs e)
    {
        TopLevel = "Market";
        RollupTitle = ((LinkButton)sender).Text;
        RollUpUnit = RollupTitle;

    }
}